home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / blockout.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  4KB  |  193 lines

  1. #include "driver.h"
  2. #include "vidhrdw/generic.h"
  3.  
  4.  
  5.  
  6. unsigned char *blockout_videoram;
  7. unsigned char *blockout_frontvideoram;
  8.  
  9.  
  10.  
  11. static void setcolor(int color,int rgb)
  12. {
  13.     int bit0,bit1,bit2,bit3;
  14.     int r,g,b;
  15.  
  16.  
  17.     /* red component */
  18.     bit0 = (rgb >> 0) & 0x01;
  19.     bit1 = (rgb >> 1) & 0x01;
  20.     bit2 = (rgb >> 2) & 0x01;
  21.     bit3 = (rgb >> 3) & 0x01;
  22.     r = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  23.  
  24.     /* green component */
  25.     bit0 = (rgb >> 4) & 0x01;
  26.     bit1 = (rgb >> 5) & 0x01;
  27.     bit2 = (rgb >> 6) & 0x01;
  28.     bit3 = (rgb >> 7) & 0x01;
  29.     g = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  30.  
  31.     /* blue component */
  32.     bit0 = (rgb >> 8) & 0x01;
  33.     bit1 = (rgb >> 9) & 0x01;
  34.     bit2 = (rgb >> 10) & 0x01;
  35.     bit3 = (rgb >> 11) & 0x01;
  36.     b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  37.  
  38.     palette_change_color(color,r,g,b);
  39. }
  40.  
  41. WRITE_HANDLER( blockout_paletteram_w )
  42. {
  43.     int oldword = READ_WORD(&paletteram[offset]);
  44.     int newword = COMBINE_WORD(oldword,data);
  45.  
  46.  
  47.     WRITE_WORD(&paletteram[offset],newword);
  48.  
  49.     setcolor(offset / 2,newword);
  50. }
  51.  
  52. WRITE_HANDLER( blockout_frontcolor_w )
  53. {
  54.     setcolor(512,data);
  55. }
  56.  
  57.  
  58.  
  59. /***************************************************************************
  60.  
  61.   Start the video hardware emulation.
  62.  
  63. ***************************************************************************/
  64. int blockout_vh_start (void)
  65. {
  66.     /* Allocate temporary bitmaps */
  67.     if ((tmpbitmap = osd_new_bitmap(Machine->drv->screen_width,Machine->drv->screen_height,Machine->scrbitmap->depth)) == 0)
  68.         return 1;
  69.  
  70.     return 0;
  71. }
  72.  
  73.  
  74. /***************************************************************************
  75.  
  76.   Stop the video hardware emulation.
  77.  
  78. ***************************************************************************/
  79. void blockout_vh_stop (void)
  80. {
  81.     osd_free_bitmap (tmpbitmap);
  82.     tmpbitmap = 0;
  83. }
  84.  
  85.  
  86.  
  87. static void updatepixels(int x,int y)
  88. {
  89.     int front,back;
  90.     int color;
  91.  
  92.  
  93.     if (x < Machine->drv->visible_area.min_x ||
  94.             x > Machine->drv->visible_area.max_x ||
  95.             y < Machine->drv->visible_area.min_y ||
  96.             y > Machine->drv->visible_area.max_y)
  97.         return;
  98.  
  99.     front = READ_WORD(&blockout_videoram[y*512+x]);
  100.     back = READ_WORD(&blockout_videoram[0x20000 + y*512+x]);
  101.  
  102.     if (front>>8) color = front>>8;
  103.     else color = (back>>8) + 256;
  104.     plot_pixel(tmpbitmap, x, y, Machine->pens[color]);
  105.  
  106.     if (front&0xff) color = front&0xff;
  107.     else color = (back&0xff) + 256;
  108.     plot_pixel(tmpbitmap, x+1, y, Machine->pens[color]);
  109. }
  110.  
  111.  
  112.  
  113. WRITE_HANDLER( blockout_videoram_w )
  114. {
  115.     int oldword = READ_WORD(&blockout_videoram[offset]);
  116.     int newword = COMBINE_WORD(oldword,data);
  117.  
  118.     if (oldword != newword)
  119.     {
  120.         WRITE_WORD(&blockout_videoram[offset],newword);
  121.         updatepixels(offset % 512,(offset / 512) % 256);
  122.     }
  123. }
  124.  
  125. READ_HANDLER( blockout_videoram_r )
  126. {
  127.    return READ_WORD(&blockout_videoram[offset]);
  128. }
  129.  
  130.  
  131.  
  132. WRITE_HANDLER( blockout_frontvideoram_w )
  133. {
  134.     COMBINE_WORD_MEM(&blockout_frontvideoram[offset],data);
  135. }
  136.  
  137. READ_HANDLER( blockout_frontvideoram_r )
  138. {
  139.    return READ_WORD(&blockout_frontvideoram[offset]);
  140. }
  141.  
  142.  
  143.  
  144. void blockout_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  145. {
  146.     if (palette_recalc())
  147.     {
  148.         /* if we ran out of palette entries, rebuild the whole screen */
  149.         int x,y;
  150.  
  151.  
  152.         for (y = 0;y < 256;y++)
  153.         {
  154.             for (x = 0;x < 320;x+=2)
  155.             {
  156.                 updatepixels(x,y);
  157.             }
  158.         }
  159.     }
  160.  
  161.     copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  162.  
  163.     {
  164.         int x,y,color;
  165.  
  166.  
  167.         color = Machine->pens[512];
  168.  
  169.         for (y = 0;y < 256;y++)
  170.         {
  171.             for (x = 0;x < 320;x+=8)
  172.             {
  173.                 int d;
  174.  
  175.  
  176.                 d = READ_WORD(&blockout_frontvideoram[y*128+(x/4)]);
  177.  
  178.                 if (d)
  179.                 {
  180.                     if (d&0x80) plot_pixel(bitmap, x  , y, color);
  181.                     if (d&0x40) plot_pixel(bitmap, x+1, y, color);
  182.                     if (d&0x20) plot_pixel(bitmap, x+2, y, color);
  183.                     if (d&0x10) plot_pixel(bitmap, x+3, y, color);
  184.                     if (d&0x08) plot_pixel(bitmap, x+4, y, color);
  185.                     if (d&0x04) plot_pixel(bitmap, x+5, y, color);
  186.                     if (d&0x02) plot_pixel(bitmap, x+6, y, color);
  187.                     if (d&0x01) plot_pixel(bitmap, x+7, y, color);
  188.                 }
  189.             }
  190.         }
  191.     }
  192. }
  193.